﻿using System;
using System.IO;
using BloggerAutoPosterService.Engine.Utils;
using NUnit.Framework;
using System.Text.RegularExpressions;

namespace BloggerAutoPosterService.Tests
{
    [TestFixture]
    public class TestUtils
    {
        [Test]
        public void Test1_TrimFeedburnerPart_Should_Work()
        {
            var url = "http://www.hanselman.com/blog/NewToolsAndNewContentASPNETVisualStudio11WebAndNET45DeveloperPreviewWithCommentary.aspx?utm_source=feedburner&amp;amp;utm_medium=feed&amp;amp;utm_campaign=Feed%3A+ScottHanselman+%28Scott+Hanselman+-+ComputerZen.com%29";
            url = url.TrimFeedburnerPart();
            Assert.AreEqual("http://www.hanselman.com/blog/NewToolsAndNewContentASPNETVisualStudio11WebAndNET45DeveloperPreviewWithCommentary.aspx", url);
        }

        [Test]
        public void Test2_Write_ToPersianDateTime_To_File_To_Analyze_It_Visually()
        {
            File.WriteAllText("tstss.htm", "خلاصه مطالب روز " + DateTime.Now.AddDays(-1).ToPersianDateTimeString());
            Assert.That(File.Exists("tstss.htm"));
        }

        [Test]
        public void Test3_Should_Remove_Email_From_Author_Name()
        {
            var pattern = @"\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*";
            var test = "vahid vahid.nasiri@gmail.com";
            test = Regex.Replace(test, pattern, string.Empty);
            var result = "vahid ";
            Assert.AreEqual(result, test);
        }

        [Test]
        public void Test4_TrimFeedburnerPart_Should_Work()
        {
            var url = "http://www.microsoft.com/download/en/details.aspx?id=27612&utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+MicrosoftDownloadCenter+%28Microsoft+Download+Center%29#tm";
            url = url.TrimFeedburnerPart();
            Assert.AreEqual("http://www.microsoft.com/download/en/details.aspx?id=27612", url);
        }
        
        [Test]
        public void Test5_HtmlDecode_Should_Work()
        {
            var data = "Wintellect\u0026#39;s Power Collections for .NET";
            data = data.HtmlDecode();
            Assert.AreEqual("Wintellect's Power Collections for .NET", data);
        }
    }
}
